package com.yyh.BookLendSystem.biz;

import java.sql.Date;
import java.sql.SQLException;

import com.yyh.BookLendSystem.dao.BookDao;
import com.yyh.BookLendSystem.util.Utils;



public class BookBiz {
	private BookDao bookDao =new BookDao();
	public  void save(String id,String name,String author,Date pressdate,int price) throws BizException {
		
		//数据校验
		Utils.check(Utils.isEmpty(name), "请输入用户名");
		Utils.check(name.length() < 2 || name.length()>50, "书名必须在2-50个字符之间");
		Utils.check(Utils.isEmpty(author), "请输入作者");
		Utils.check(author.length()<2 || author.length()>20, "作者名必须在2-20个字之间");
		
		//其他字段自行验证
		try {
			if(Utils.isEmpty(id)) {
				bookDao.insert( id,name, author, pressdate, price);
			}else {
				bookDao.update( id,name, author, pressdate, price);
			}
		} catch (SQLException e) {
			
			throw new BizException("系统异常,请联系管理员",e);
		}
	}
}
